package com.ruoyi.web.controller.tool;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.framework.config.ServerConfig;
import com.ruoyi.tool.service.IPDFToolsService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * swagger pdf切割工具
 * 
 * @author ruoyi
 */
@Api("小工具-pdf")
@RestController
@RequestMapping("/tool/pdf")
public class PDFController extends BaseController {
    @Autowired
    private ServerConfig serverConfig;

    @Autowired
    private IPDFToolsService pdfToolsService;




    @ApiOperation("切分pdf")
    @PostMapping("/split")
    public R<String> save(@RequestParam("pdfFile") MultipartFile pdfFile) throws Exception
    {
        // 上传文件路径
        String filePath = RuoYiConfig.getUploadPath();
        // 上传并返回新文件名称
        String fileName = FileUploadUtils.upload(filePath, pdfFile);

        logger.info("pdfFile.getOriginalFilename():{}", pdfFile.getOriginalFilename());
        logger.info("pdfFile.getName():{}", pdfFile.getName());
        logger.info("filePath:{}", filePath);
        logger.info("fileName:{}", fileName);
      //  pdfSplitService.split(fileName);
        String absoluteFile = filePath + fileName.replace("/profile/upload","");
        logger.info("absoluteFile:{}", absoluteFile);
        pdfToolsService.leftRightSplit(absoluteFile);

      //  String url = serverConfig.getUrl() + fileName.replace(".pdf","_output.pdf");
        String url = fileName.replace(".pdf","_output.pdf");
        return R.ok(url);
    }





}
